﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using HtmlAgilityPack;

namespace ObservadorPeplau.API.Business
{
    public class Comment
    {
        public int Id { get; set; }
        public Author Author { get; set; }
        public DateTime DateTime { get; set; }
        public string Text{ get; set; }
        [XmlIgnore]
        public Comment Parent { get; set; }
        [XmlIgnore]
        public List<Comment> Children { get; set; }

        public Comment()
        {
            Id = -1;
            Author = null;
            DateTime = DateTime.Now;
            Text = "";
            Parent = null;
            Children = new List<Comment>();
            IsRead = false;
        }

        [XmlIgnore]
        public bool IsRead
        {
            get { return DiscussionManager.IsMarked(this, Constants.CommentReadKey); }
            set { DiscussionManager.SetMarked(this, Constants.CommentReadKey, value); }
        }

        [XmlIgnore]
        public string TextWithoutHtml
        {
            get
            {
                var strText = "";
                var textDoc = new HtmlDocument();
                textDoc.LoadHtml(@Text);
                return textDoc.DocumentNode.InnerText;
            }
            set { Text = value; }
        }
    }
}
